avalon.ready(function(){

    // var request_base_url = "/";
    var request_base_url = "/cloud/";
    function url(request_uri){
        return request_base_url+request_uri;
    }
    //编写金额过滤器
    avalon.filters.myCurrency = function (amount, symbol, fractionSize) {
        if(amount==null||amount==""){
            return amount;
        }
        return avalon.filters.currency(amount, symbol, fractionSize);
    };
	avalon.log("加载avalon完毕，开始构建根vm与加载其他模块");
    /**************************function_add************************************/
    var login = avalon.define({
        $id:'login',
        userName:"",
        password:"",
        randomCode:"",
        errorUserNameContent:"",
        errorPasswordContent:"",
        errorRandomCodeContent:"",
        getRandomCode:url("/user/randomCode"),
        login: function(){
            if($.trim(login.userName)==""){
                login.errorUserNameContent="用户名不能为空";
            }else{
                login.errorUserNameContent="";
            }
            if($.trim(login.password)==""){
                login.errorPasswordContent="密码不能为空";
            }else{
                login.errorPasswordContent="";
            }
            if($.trim(login.randomCode)==""){
                login.errorRandomCodeContent="验证码不能为空";
            }else if($.trim(login.randomCode).length!=4){
                login.errorRandomCodeContent="验证码错误，请重新输入";
            }else{
                login.errorRandomCodeContent="";
            }
            if($.trim(login.userName)!=""&&$.trim(login.password)!=""&&$.trim(login.randomCode)!=""&&$.trim(login.randomCode).length==4){
                login.toLogin();
            }
        },
        getUserSession:function(){
            if(sessionStorage.loginStatus!=1){
                $.ajax({
                    type : "post",
                    url: url("user/getUserSession"),
                    success : function(result) {
                        if(result.code=="000000")
                        {
                            login.saveUserInfo(result);
                            top.location.href=request_base_url+"html/index.html";
                        }else{
                            sessionStorage.clear();
                            top.location.href=root.load("");
                        }
                    },error:function(e){
                        console.log(e)
                    }
                });
            }
        },
        changeRandomCode:function(){
            login.getRandomCode = request_base_url+"user/randomCode?time="+new Date().getTime();
        },
        loginEnter:function(){
            if (event.keyCode == "13") {//keyCode=13是回车键
                login.login();
            }
        },
        saveUserInfo:function(result){
            sessionStorage.trueName=result.data.trueName;
            console.log(result.data);
            var userPower = result.data.userPower;
            sessionStorage.userPower_navCloud =userPower.navCloud;
            sessionStorage.userPower_cloudInPerson =userPower.cloudInPerson;
            sessionStorage.userPower_cloudOutPerson =userPower.cloudOutPerson;
            sessionStorage.userPower_trackingAddSigned =userPower.trackingAddSigned;
            sessionStorage.userPower_trackingAddBack =userPower.trackingAddBack;
            sessionStorage.userPower_trackingAddBackOut =userPower.trackingAddBackOut;

            sessionStorage.userPower_sendPiecesSearch =userPower.sendPiecesSearch;

            sessionStorage.userPower_navPerson =userPower.navPerson;
            sessionStorage.userPower_userList =userPower.userList;
            sessionStorage.userPower_userAdd =userPower.userAdd;
            sessionStorage.userPower_userUpdate =userPower.userUpdate;
            sessionStorage.userPower_userDelete =userPower.userDelete;

            sessionStorage.userPower_navSystem =userPower.navSystem;
            sessionStorage.userPower_companyList =userPower.companyList;
            sessionStorage.userPower_companyAdd =userPower.companyAdd;
            sessionStorage.userPower_companyUpdate =userPower.companyUpdate;
            sessionStorage.userPower_companyDelete =userPower.companyDelete;

            sessionStorage.userPower_companyPointList =userPower.companyPointList;
            sessionStorage.userPower_companyPointListAll =userPower.companyPointListAll;
            sessionStorage.userPower_companyPointListCompany =userPower.companyPointListCompany;
            sessionStorage.userPower_companyPointListCompanyPoint =userPower.companyPointListCompanyPoint;
            sessionStorage.userPower_companyPointAdd =userPower.companyPointAdd;
            sessionStorage.userPower_companyPointUpdate =userPower.companyPointUpdate;
            sessionStorage.userPower_companyPointDelete =userPower.companyPointDelete;
            sessionStorage.userPower_roleAdd =userPower.roleAdd;
            sessionStorage.userPower_functionRole=userPower.functionRole;

            sessionStorage.userPower_trackingFlow=userPower.trackingFlow;
            sessionStorage.userPower_verify=userPower.verify;
            sessionStorage.userPower_batch_signed=userPower.batchSigned;
            sessionStorage.userPower_modify_collect_type=userPower.modifyCollectType;


            if(result.data.companyId){
                sessionStorage.companyId=result.data.companyId;
            }
            if(result.data.companyPointName){
                sessionStorage.companyPointName=result.data.companyPointName;
            }
            if(result.data.companyType){
                sessionStorage.companyType=result.data.companyType;
            }
            sessionStorage.userType=result.data.userType;
            sessionStorage.page_now = '../html/home_cloud.html';
            sessionStorage.page = "home_cloud.html";
            sessionStorage.loginStatus =1;//代表已登录
        },
        toLogin:function(){
            $.ajax({
                type : "post",
                url: url("user/login"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify(login.$model),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        login.saveUserInfo(result);
                        top.location.href=request_base_url+"html/index.html";
                    }else if(result.code=="200003"){
                        login.errorUserNameContent=result.message;
                        login.changeRandomCode();
                    }else if(result.code=="200004"||result.code=="200007"){
                        login.errorPasswordContent=result.message;
                        login.changeRandomCode();
                    }else if(result.code=="200006"||result.code=="200005"){
                        login.errorRandomCodeContent=result.message;
                        login.changeRandomCode();
                    }else{
                        login.errorRandomCodeContent=result.message;
                    }
                },error:function(e){
                    console.log(e)
                    login.changeRandomCode();
                }
            });
        }
    });
	/**************************tracking_add************************************/

	var tracking_add = avalon.define({
		$id:'tracking_add',
        companyName:sessionStorage.tracking_add_companyName,
        companyPointShortName:sessionStorage.tracking_add_companyPointShortName,
        srcCompanyPointId:sessionStorage.tracking_add_srcCompanyPointId,
        userName: sessionStorage.tracking_add_userName,
        trackingNumber:"",
        isCollect:0,
        collectMoney:"",
        senderCode:sessionStorage.tracking_add_senderCode,
        tracking_list:[],
        status:sessionStorage.tracking_status,
        operationName:sessionStorage.operationName,
        successCount:0,
        changeIsCollect:function(){
            $("#trackingNumber").focus();
        },
		tracking_add: function(event){
            tracking_add.isCollect= tracking_add.isCollect==0||tracking_add.isCollect==undefined||tracking_add.isCollect==false?0:1;
			if (event.keyCode == "13") {//keyCode=13是回车键

                if($.trim(tracking_add.trackingNumber)!=""){
                    $.ajax({
                        type : "post",
                        url: url("tracking/addLog"),
                        dataType : 'json',
                        contentType:'application/json',
                        data: JSON.stringify(tracking_add.$model),
                        success : function(result) {
                            tracking_add.trackingNumber="";
                            tracking_add.collectMoney="";
                            $("#trackingNumber").focus();
                            if(result.code=="000000"){
                                result.status=true;
                                tracking_add.successCount = tracking_add.successCount+1;
                                $("audio").attr("src","../music/success.wav");
                            }else{
                                result.status=false;
                                $("audio").attr("src","../music/fail.wav");
                            }
                            tracking_add.tracking_list.reverse();
                            tracking_add.tracking_list.push(result);
                            tracking_add.tracking_list.reverse();
                            $("audio").get(0).play();
                        }
                    });
                }
            }
		}
	});

/**************************tracking_add_back************************************/

var tracking_add_back = avalon.define({

    $id:'tracking_add_back',
    problem:"",
    problemError:0,
    trackingNumber:"",
    tracking_list:[],
    status:sessionStorage.tracking_status,
    successCount:0,
    checkProblem:function(event){
        if($.trim(tracking_add_back.problem)!=""){
            tracking_add_back.problemError=0;
            tracking_add_back.tracking_add(event);
        }else{
            tracking_add_back.problemError=1;
        }
    },
    tracking_add: function(event){
        if (event.keyCode == "13") {//keyCode=13是回车键
            if($.trim(tracking_add_back.problem)==""){
                tracking_add_back.problemError=1;
                return ;
            }
            if($.trim(tracking_add_back.trackingNumber)!="") {
                $.ajax({
                    type: "post",
                    url: url("tracking/addLog"),
                    dataType: 'json',
                    contentType:'application/json',
                    data: JSON.stringify(tracking_add_back.$model),
                    success: function (result) {
                        tracking_add_back.trackingNumber = "";
                        $("#trackingNumber").focus();
                        if (result.code == "000000") {
                            result.status=true;
                            tracking_add_back.successCount = tracking_add.successCount+1;
                            $("audio").attr("src","../music/success.wav");
                        } else {
                            result.status=false;
                            $("audio").attr("src","../music/fail.wav");
                        }
                        tracking_add_back.tracking_list.reverse();
                        tracking_add_back.tracking_list.push(result);
                        tracking_add_back.tracking_list.reverse();
                        $("audio").get(0).play();
                    }
                });
            }
        }
    }
});

/**************************走件流程 tracking_flow************************************/

var tracking_flow = avalon.define({
    $id:'tracking_flow',
    trackingNumber:"",
    srcCompanyPointName:"",
    cloudPointName:"",
    status:-1,
    senderName:"",
    senderCode:"",
    senderCompanyPointName:"",
    collectMoney:"",
    isCollect:-1,
    trackingLogList:[],
    trackingModifyLogList:[],
    driverName:"",
    getInfo: function(event){
        if (event.keyCode == "13") {//keyCode=13是回车键
            if($.trim(tracking_flow.trackingNumber)!="") {
                tracking_flow.goGetInfo();
            }
        }
    },
    goGetInfo:function(){
        $.ajax({
            type: "post",
            url: url("tracking/getInfo"),
            dataType: 'json',
            contentType:'application/json',
            data: JSON.stringify({trackingNumber:tracking_flow.trackingNumber}),
            success: function (result) {
                if(result.code=="000000"){
                    var trackingInfo = result.data;
                    tracking_flow.srcCompanyPointName = trackingInfo.srcCompanyPointName;
                    tracking_flow.cloudPointName = trackingInfo.cloudPointName;
                    tracking_flow.status = trackingInfo.status;
                    tracking_flow.senderName = trackingInfo.senderName;
                    tracking_flow.senderCode = trackingInfo.senderCode;
                    tracking_flow.senderCompanyPointName = trackingInfo.senderCompanyPointName;
                    tracking_flow.collectMoney = trackingInfo.collectMoney;
                    tracking_flow.isCollect = trackingInfo.isCollect;
                    tracking_flow.trackingLogList = trackingInfo.trackingLogList;
                    tracking_flow.driverName = trackingInfo.driverName;
                    tracking_flow.changeTab(1);
                }else{
                    alert(result.message);
                }
            }
        });
    },
    modifyCollectType:function(type){

        var typeString = type==0?"代收单":"普通单";
        if(confirm("确定将运单"+tracking_flow.trackingNumber+"修改为"+typeString+"？")){
            $.ajax({
                type: "post",
                url: url("tracking/modifyCollectType"),
                dataType: 'json',
                contentType:'application/json',
                data: JSON.stringify({trackingNumber:tracking_flow.trackingNumber,type:type}),
                success: function (result) {
                    if(result.code=="000000"){
                        var trackingDO = result.data;
                        tracking_flow.isCollect=trackingDO.isCollect;
                        tracking_flow.changeTab(2);
                        alert("修改成功！");
                    }else{
                        alert(result.message);
                    }
                }
            });
        }
    },
    changeTab:function(tabType){
        if(tabType==1){
            $("#flowInfoTab").addClass("onChoice");
            $("#flowInfo").show();
            $("#modifyLogTab").removeClass("onChoice");
            $("#modifyLog").hide();
        }else if(tabType==2){
            $("#flowInfoTab").removeClass("onChoice");
            $("#flowInfo").hide();
            $("#modifyLogTab").addClass("onChoice");
            $("#modifyLog").show();
            if(tracking_flow.trackingNumber!=''){
                $.ajax({
                    type: "post",
                    url: url("tracking/getModifyCollectLogList"),
                    dataType: 'json',
                    contentType:'application/json',
                    data: JSON.stringify({trackingNumber:tracking_flow.trackingNumber}),
                    success: function (result) {
                        tracking_flow.trackingModifyLogList = [];
                        if(result.code=="000000"){
                            tracking_flow.trackingModifyLogList = result.data;
                        }
                    }
                });
            }
        }
    }
});
    /**************************tracking_add_back_out************************************/

    var tracking_add_back_out = avalon.define({
        $id:'tracking_add_back_out',
        trackingNumber:"",
        tracking_list:[],
        status:sessionStorage.tracking_status,
        successCount:0,
        problemOut:"",
        tracking_add: function(event){
            if (event.keyCode == "13") {//keyCode=13是回车键
                if($.trim(tracking_add_back_out.trackingNumber)!=""){
                    $.ajax({
                        type: "post",
                        url: url("tracking/addLog"),
                        dataType: 'json',
                        contentType:'application/json',
                        data: JSON.stringify(tracking_add_back_out.$model),
                        success: function (result) {
                            tracking_add_back_out.trackingNumber = "";
                            $("#trackingNumber").focus();
                            if (result.code == "000000") {
                                result.status=true;
                                tracking_add_back_out.successCount = tracking_add.successCount+1;
                                $("audio").attr("src","../music/success.wav");
                            } else {
                                result.status=false;
                                $("audio").attr("src","../music/fail.wav");
                            }
                            tracking_add_back_out.tracking_list.reverse();
                            tracking_add_back_out.tracking_list.push(result);
                            tracking_add_back_out.tracking_list.reverse();
                            $("audio").get(0).play();
                        }
                    });
                }
            }
        }
    });
    /**************************入仓cloud_in_person************************************/

    var cloud_in_person = avalon.define({

        $id:'cloud_in_person',
        code: "",
        driverName:"",
        isError:"",
        errorMessage:"",
        goScan: function(event){
            if (event.keyCode == "13") {//keyCode=13是回车键
                if($.trim(cloud_in_person.code)==""){
                    cloud_in_person.isError=true;
                    cloud_in_person.errorMessage="请扫描或输入站点编号";
                    $("#goScan").focus();
                }else{
                    $.ajax({
                        type : "post",
                        url: url("company/findPointByCode"),
                        dataType : 'json',
                        contentType:'application/json',
                        data: JSON.stringify(cloud_in_person.$model),
                        success : function(result) {
                            if(result.code=="000000"){
                                sessionStorage.tracking_status=0;
                                sessionStorage.tracking_add_companyName=result.data.companyName;
                                sessionStorage.tracking_add_companyPointShortName=result.data.shortName;
                                sessionStorage.tracking_add_srcCompanyPointId=result.data.id;
                                sessionStorage.tracking_add_userName=cloud_in_person.driverName;

                                tracking_add.status=0;
                                tracking_add.companyName=result.data.companyName;
                                tracking_add.companyPointShortName=result.data.shortName;
                                tracking_add.srcCompanyPointId=result.data.id;
                                tracking_add.userName=cloud_in_person.driverName;
                                sessionStorage.operationName="入仓扫描";
                                tracking_add.operationName="入仓扫描";
                                root.load('tracking_add.html',1);
                            }else{
                                cloud_in_person.isError=true;
                                cloud_in_person.errorMessage=result.message;
                            }
                        }
                    });
                }
            }
        }
    });

    /**************************派件cloud_out_person************************************/
    var cloud_out_person = avalon.define({

        $id:'cloud_out_person',
        userCode: "",
        isError:"",
        errorMessage:"",
        goScan: function(event){
            if (event.keyCode == "13") {//keyCode=13是回车键
                if($.trim(cloud_out_person.userCode)==""){
                    cloud_out_person.isError=true;
                    cloud_out_person.errorMessage="请扫描或输入快递员编号";
                    $("#goScan").focus();
                }else{
                    $.ajax({
                        type : "post",
                        url: url("user/findSenderByCode"),
                        dataType : 'json',
                        contentType:'application/json',
                        data: JSON.stringify({code:cloud_out_person.userCode}),
                        success : function(result) {
                            cloud_out_person.userCode="";
                            if(result.code=="000000"){
                                sessionStorage.tracking_status=1;
                                sessionStorage.tracking_add_companyName=result.data.companyName;
                                sessionStorage.tracking_add_companyPointShortName=result.data.companyPointShortName;
                                sessionStorage.tracking_add_senderCode=result.data.code;
                                sessionStorage.tracking_add_srcCompanyPointId=result.data.companyPointId;
                                sessionStorage.tracking_add_userName=result.data.trueName;

                                tracking_add.status=1;
                                tracking_add.companyName=result.data.companyName;
                                tracking_add.companyPointShortName=result.data.shortName;
                                tracking_add.senderCode=result.data.code;
                                tracking_add.srcCompanyPointId=result.data.id;
                                tracking_add.userName=result.data.trueName;
                                sessionStorage.operationName="派件扫描";
                                tracking_add.operationName="派件扫描";
                                root.load('tracking_add.html',2);

                            }else{
                                cloud_out_person.isError=true;
                                cloud_out_person.errorMessage=result.message;
                            }
                        }
                    });
                }
            }
        }
    });

    /**************************回仓cloud_back_person************************************/
    var cloud_back_person = avalon.define({

        $id:'cloud_back_person',
        userCode: "",
        isError:"",
        errorMessage:"",
        goScan: function(event){
            if (event.keyCode == "13") {//keyCode=13是回车键
                $.ajax({
                    type : "post",
                    url: url("user/findByCode"),
                    dataType : 'json',
                    contentType:'application/json',
                    data: {userCode:cloud_back_person.userCode},
                    success : function(result) {
                        cloud_back_person.userCode="";
                        if(result.code=="000000"){
                            sessionStorage.tracking_add_userCode = result.data.code;
                            sessionStorage.tracking_add_userCodePreLabel="快递员编号";
                            sessionStorage.tracking_add_trueName = result.data.trueName;
                            sessionStorage.tracking_add_companyPointShortName=result.data.companyPointShortName;
                            root.load('tracking_add.html');
                        }else{
                            cloud_back_person.isError=true;
                            cloud_back_person.errorMessage=result.message;
                        }
                    }
                });
            }
        }
    });
    /**************************退件cloud_back_out_person************************************/
    var cloud_back_out_person = avalon.define({

        $id:'cloud_back_out_person',
        userCode: "",
        isError:"",
        errorMessage:"",
        goScan: function(event){
            if (event.keyCode == "13") {//keyCode=13是回车键
                $.ajax({
                    type : "post",
                    url: url("user/findByCode"),
                    dataType : 'json',
                    contentType:'application/json',
                    data: {userCode:cloud_back_out_person.userCode},
                    success : function(result) {
                        cloud_back_out_person.userCode="";
                        if(result.code=="000000"){
                            sessionStorage.tracking_add_userCode = result.data.code;
                            sessionStorage.tracking_add_userCodePreLabel="快递员编号";
                            sessionStorage.tracking_add_trueName = result.data.trueName;
                            sessionStorage.tracking_add_companyPointShortName=result.data.companyPointShortName;
                            root.load('tracking_add.html');
                        }else{
                            cloud_back_out_person.isError=true;
                            cloud_back_out_person.errorMessage=result.message;
                        }
                    }
                });
            }
        }
    });
    /**************************派件查询************************************/
    var send_pieces_search = avalon.define({
        $id:'send_pieces_search',
        driverCode: "",
        senderCode:"",
        trackingNumber:"",
        srcCompanyId:"",
        srcCompanyPointId:"",
        cloudId:"",
        status:"",
        startTime:"",
        endTime:"",
        senderName:"",
        collectStatus:"",
        tracking_list:[],
        senderCompanyPointId:"",
        srcCompanyPointList:[],
        srcCompanyList:[],
        cloudList:[],
        cloudPointList:[],
        sendList:[],
        sendPointList:[],
        senderCompanyId:"",
        cloudPointId:"",
        pageNum:"",
        pageSize:"",
        initDate :0,
        changeSrcCompany:function(){
            if(send_pieces_search.srcCompanyId==""){
                send_pieces_search.srcCompanyPointId="";
                send_pieces_search.srcCompanyPointList=[];
            }else{
                send_pieces_search.initSrcCompanyPoint();
            }
        },
        initSrcCompanyPoint:function(){
            $.ajax({
                type : "post",
                url: url("company/pagePoint"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify({companyId:send_pieces_search.srcCompanyId,companyType:2,pageNum:paging.firstPageNum,pageSize:paging.maxSize,companyPointSearchType:3}),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        send_pieces_search.srcCompanyPointId="";
                        send_pieces_search.srcCompanyPointList = result.data.list;
                    }
                }
            });
        },
        initSrcCompany:function(){
            $.ajax({
                type : "post",
                url: url("company/page"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify({type:2,pageNum:paging.firstPageNum,pageSize:paging.maxSize,companySearchType:3}),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        send_pieces_search.srcCompanyId="";
                        send_pieces_search.srcCompanyList = result.data.list;
                    }
                }
            });
        },
        changeCloud:function(){
            if(send_pieces_search.cloudId==""){
                send_pieces_search.cloudPointId="";
                send_pieces_search.cloudPointList=[];
            }else{
                send_pieces_search.initCloudPoint();
            }
        },
        initCloud:function(){
            $.ajax({
                type : "post",
                url: url("company/page"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify({type:1,pageNum:paging.firstPageNum,pageSize:paging.maxSize,companySearchType:3}),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        send_pieces_search.cloudList="";
                        send_pieces_search.cloudList = result.data.list;
                    }
                }
            });
        },
        initCloudPoint:function(){
            $.ajax({
                type : "post",
                url: url("company/pagePoint"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify({companyId:send_pieces_search.cloudId,companyType:1,pageNum:paging.firstPageNum,pageSize:paging.maxSize,companyPointSearchType:3}),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        send_pieces_search.cloudPointList="";
                        send_pieces_search.cloudPointList = result.data.list;
                    }
                }
            });
        },
        initSend:function(){
            $.ajax({
                type : "post",
                url: url("company/page"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify({type:0,pageNum:paging.firstPageNum,pageSize:paging.maxSize,companySearchType:3}),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        send_pieces_search.sendList="";
                        send_pieces_search.sendList = result.data.list;
                    }
                }
            });
        },
        initSendPoint:function(){
            $.ajax({
                type : "post",
                url: url("company/pagePoint"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify({companyId:send_pieces_search.senderCompanyId,companyType:0,pageNum:paging.firstPageNum,pageSize:paging.maxSize,companyPointSearchType:3}),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        send_pieces_search.sendPointList="";
                        send_pieces_search.sendPointList = result.data.list;
                    }
                }
            });
        },
        changeSend:function(){
            if(send_pieces_search.senderCompanyId==""){
                send_pieces_search.senderCompanyPointId="";
                send_pieces_search.sendPointList=[];
            }else{
                send_pieces_search.initSendPoint();
            }
        },
        pageEnter:function(){
            if (event.keyCode == "13") {//keyCode=13是回车键
                send_pieces_search.page();
            }
        },
        exportExcel:function(){
            window.location.href=url("exportExcel/tracking")+"?+trackingNumber="+send_pieces_search.trackingNumber;
        },
        page:function(){
            send_pieces_search.startTime=$("#tracking_start").val();
            send_pieces_search.endTime=$("#tracking_end").val();
            send_pieces_search.pageNum = paging.pageNum;
            send_pieces_search.pageSize = paging.pageSize;
            $.ajax({
                type : "post",
                url: url("tracking/page"),
                dataType : 'json',
                contentType:'application/json',
                data:JSON.stringify(send_pieces_search.$model),
                success : function(result) {

                    if(result.code=="000000"){
                        send_pieces_search.tracking_list = [];
                        send_pieces_search.tracking_list = result.data.list;
                        paging.pageNum = result.data.pageNum;
                        paging.pageSize = result.data.pageSize;
                        paging.pageCount = result.data.pageCount;
                        paging.total = result.data.total;
                    }else{
                        // alert(result.message);
                    }
                }
            });
        },
        collect:function(tracking_number){
            collect.tracking_number = tracking_number;
            root.load('collect.html',6);
        }
    });
    /**************************批量签收************************************/
    var tracking_batch_signed = avalon.define({
        $id:'tracking_batch_signed',
        senderCode:"",
        startTime:"",
        endTime:"",
        tracking_list:[],
        checkState:"",
        pageNum:1,
        pageSize:9999,
        status:1,
        total:0,
        isCollect:0,
        page:function(){

            if($.trim(tracking_batch_signed.senderCode)!=""){
                tracking_batch_signed.startTime=$("#tracking_start").val();
                tracking_batch_signed.endTime=$("#tracking_end").val();
                tracking_batch_signed.tracking_list=[];
                $("#tip").text("正在查询请稍候......").show();
                $.ajax({
                    type : "post",
                    url: url("tracking/page"),
                    dataType : 'json',
                    contentType:'application/json',
                    data:JSON.stringify(tracking_batch_signed.$model),
                    success : function(result) {
                        if(result.code=="000000"){
                            $("#tip").hide();
                            var trackingList = result.data.list;
                            tracking_batch_signed.checkState=1;
                            tracking_batch_signed.total = result.data.total;
                            for(var o in trackingList){
                                trackingList[o].checked = true;
                            }
                            tracking_batch_signed.tracking_list = trackingList;
                            if(tracking_batch_signed.tracking_list.length==0){
                                $("#tip").text("查询完毕，无数据").show();
                            }
                        }else{
                            $("#tip").text("系统错误，请联系管理员").show();
                        }
                    },
                    error:function(){
                        $("#tip").text("系统错误，请联系管理员").show();
                    }
                });
            }
        },
        clearStartTime:function(){
            $('#tracking_start').val("");
        },
        clearEndTime:function(){
            $('#tracking_end').val("");
        },
        changeCheckState:function(){
            var flag = tracking_batch_signed.checkState==1?false:true;
            tracking_batch_signed.checkState = tracking_batch_signed.checkState==1?0:1;
            for(var o in tracking_batch_signed.tracking_list){
                tracking_batch_signed.tracking_list[o].checked= flag;
            }

        },
        changeOneCheckState:function(){
            for(var o in tracking_batch_signed.tracking_list){
                if(!tracking_batch_signed.tracking_list[o].checked){
                    tracking_batch_signed.checkState = 0;
                }
            }
        },
        goSigned:function(){

            var size = tracking_batch_signed.tracking_list.length;

            for(var i =0;i< size ;i++){
                if(tracking_batch_signed.tracking_list[i].checked){
                    var trackingNumber = tracking_batch_signed.tracking_list[i].trackingNumber;
                    $.ajax({
                        async:false,//for循环内 同步发起ajax请求
                        type : "post",
                        url: url("tracking/addLog"),
                        dataType : 'json',
                        contentType:'application/json',
                        data: JSON.stringify({trackingNumber:trackingNumber,status:2}),
                        success : function(result) {
                            if(result.code=="000000"){
                                tracking_batch_signed.tracking_list[i].status=2;
                            }else{
                                tracking_batch_signed.tracking_list[i].status=6;
                            }
                        }
                    });
                }
            }
        }
    });
    /*************************代收页面*****************************/
    var collect = avalon.define({
        $id:'collect',
        tracking_number:"",
        money:"",
        saveStatus:0,
        errorMessage:"",
        save: function(){
            var exp = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
            if(exp.test(collect.money)){
                collect.saveStatus=0;
                if(confirm("代收金额"+collect.money+"元，确认签收？")){
                    $.ajax({
                        type : "post",
                        url: url("tracking/collect"),
                        dataType : 'json',
                        contentType:'application/json',
                        data: {trackingNumber:collect.tracking_number,money:collect.money},
                        success : function(result) {
                            if(result.code=="000000")
                            {
                                collect.saveStatus=1;
                            }else{
                                collect.saveStatus=2;
                                collect.errorMessage=result.message;
                            }
                        }
                    });
                }
            }else{
                collect.saveStatus=2;
                collect.errorMessage="金额填写有误";
            }
        }
    });
	/*************************分页*****************************/

	var paging = avalon.define({
		$id:'paging',
		pageNum:1,
		pageSize:10,
		pageCount:1,
		total:0,
		maxSize:999,
		firstPageNum:1,
		subPage: function(){
			paging.pageNum = paging.pageNum<=1?1:paging.pageNum-1;
            paging.executePage();
		},
		addPage: function(){

			paging.pageNum = paging.pageNum>=paging.pageCount?paging.pageNum:paging.pageNum+1;
            paging.executePage();
		},
		firstPage: function(){
			paging.pageNum = 1;
            paging.executePage();
		},
		lastPage: function(){
			paging.pageNum = paging.pageCount;
            paging.executePage();
		},
        executePage:function(){
            if(sessionStorage.page=="company_list.html"){
                company_list.page();
            }
            if(sessionStorage.page=="company_point_list.html"){
                company_point_list.page();
            }
            if(sessionStorage.page=="send_pieces_search.html"){
                send_pieces_search.page();
            }
            if(sessionStorage.page=="user_list.html"){
                user_list.page();
            }
            if(sessionStorage.page=="car_list.html"){
                car_list.page();
            }
            if(sessionStorage.page=="role_list.html"){
                role_list.page();
            }
        }
	});
	/*************************角色列表*****************************/
	var role_list = avalon.define({
		$id:'role_list',
        roleList:[],
        pageNum:"",
        pageSize:"",
		removeItem:function(id){
			if(confirm("确定删除本条数据？")){
				$.ajax({
					type : "post",
					url: url("role/delete"),
					dataType : 'json',
                    contentType:'application/json',
					data: JSON.stringify({id:id}),
					success : function(result) {
						if(result.code=="000000")
						{
							paging.pageNum=1;
                            role_list.page();
						}
					}
				});
			}
		},
        goUpdate:function(id){
            role_add.operate=1;
            $.ajax({
                type : "post",
                url: url("role/find"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify({id:id}),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        role_add.id=result.data.id;
                        role_add.name=result.data.name;
                        role_add.remark=result.data.remark;
                    }
                }
            });
            root.load('role_add.html',15);
		},
        goSave:function(){
            role_add.operate=0;
            role_add.id="";
            role_add.name="";
            role_add.remark="";
            root.load('role_add.html',15);
        },
        page:function(){
            role_list.pageNum = paging.pageNum;
            role_list.pageSize = paging.pageSize;
            $.ajax({
                type : "post",
                url: url("role/page"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify(role_list.$model),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        role_list.roleList = result.data.list;
                        paging.pageNum = result.data.pageNum;
                        paging.pageSize = result.data.pageSize;
                        paging.pageCount = result.data.pageCount;
                        paging.total = result.data.total;
                    }
                }
            });
        },
		listRole: function(){

            role_list.pageNum = paging.firstPageNum;
            role_list.pageSize = paging.maxSize;
			$.ajax({
				type : "post",
				url: url("role/page"),
				dataType : 'json',
                contentType:'application/json',
				data: JSON.stringify(role_list.$model),
				success : function(result) {
					if(result.code=="000000")
					{
						role_list.roleList = result.data.list;
						paging.pageNum = result.data.pageNum;
						paging.pageSize = result.data.pageSize;
						paging.pageCount = result.data.pageCount;
						paging.total = result.data.total;
					}
				}
			});
		}
	});

	/*************************添加角色*****************************/
	var role_add = avalon.define({
		$id:'role_add',
        id:"",
		name:"",
		remark:"",
        saveStatus:0,
        errorMessage:"",
        operate:"",//操作：0-添加，1-修改
		save: function(){
			$.ajax({
				type : "post",
				url: url("role/add"),
				dataType : 'json',
                contentType:'application/json',
				data: JSON.stringify(role_add.$model),
				success : function(result) {
					if(result.code=="000000")
					{
                        role_add.id="";
                        role_add.name="";
                        role_add.remark="";
                        role_add.saveStatus=1;
					}else{
                        role_add.saveStatus=2;
                        role_add.errorMessage=result.message;
					}
				}
			});
		},
        update: function(){
            $.ajax({
                type : "post",
                url: url("role/update"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify(role_add.$model),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        role_add.id="";
                        role_add.name="";
                        role_add.remark="";
                        root.load("role_list.html",15);
                    }else{
                        role_add.saveStatus=2;
                        role_add.errorMessage=result.message;
                    }
                }
            });
        }
	});
    /*************************角色权限*****************************/
    var function_role = avalon.define({
        $id:'function_role',
        roleId:"",
        moduleList:[],
        addUserRoleList:[],
        addUserChecked:0,
        checkAddUser:function(){
            if($("#function_1").is(':checked')){
                function_role.addUserChecked = 1;
            }else{
                function_role.addUserChecked = 0;
            }
        },
        init: function(){
            $.ajax({
                type : "post",
                url: url("function/page"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify(function_role.$model),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        function_role.moduleList=result.data;
                        function_role.addUserChecked=0;
                        for(var o in function_role.moduleList){
                            var module = function_role.moduleList[o];
                            if(module.id==1){
                                var functionRoleList = module.functionRoleList;
                                for(var i in functionRoleList){
                                    if(functionRoleList[i].functionId==1&&functionRoleList[i].pass==1){
                                        function_role.addUserChecked=1;
                                    }
                                }
                            }
                        }
                    }
                }
            });
            $.ajax({
                type : "post",
                url: url("role/listAddUserRoleManage"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify(function_role.$model),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        function_role.addUserRoleList=result.data;
                    }
                }
            });

        },
        changeRole:function(roleId,dom){
            $(dom).parent().siblings().removeClass("roleChecked");
            $(dom).parent().addClass("roleChecked");
            function_role.roleId = roleId;
            function_role.init();
        },
        save:function(){
            if(confirm("确认修改该角色的权限？")){
                var moduleList = function_role.moduleList;
                if(moduleList!=[]){
                    for(var o in moduleList){
                        var functionRoleList = moduleList[o].functionRoleList;
                        for(var i in functionRoleList){
                            var functionRole = functionRoleList[i];
                            functionRole.pass= functionRole.pass==0||functionRole.pass==undefined||functionRole.pass==false?0:1;
                        }
                    }
                }
                var addUserRoleList = function_role.addUserRoleList;
                if(addUserRoleList!=[]){
                    for(var o in addUserRoleList){
                        var addUserRole = addUserRoleList[o];
                        addUserRole.pass= addUserRole.pass==0||addUserRole.pass==undefined||addUserRole.pass==false?0:1;
                    }
                }

                $.ajax({
                    type : "post",
                    url: url("function/saveFunctionRole"),
                    dataType : 'json',
                    contentType:'application/json',
                    data: JSON.stringify(function_role.$model),
                    success : function(result) {
                        if(result.code=="000000")
                        {
                            alert("角色权限已变更！");
                            function_role.init();
                        }
                    }
                });
            }
        }
    });
    /*************************公司列表*****************************/
    var company_list = avalon.define({
        $id:'company_list',
        company_list:[],
        type:"",
        pageNum:"",
        pageSize:"",
        companySearchType:4,
        removeItem:function(id){
            if(confirm("确定删除本条数据？")){
                $.ajax({
                    type : "post",
                    url: url("company/delete"),
                    dataType : 'json',
                    contentType:'application/json',
                    data: JSON.stringify({id:id}),
                    success : function(result) {
                        if(result.code=="000000")
                        {
                            paging.pageNum=1;
                            company_list.page();
                        }
                    }
                });
            }
        },
        goUpdate:function(id){
            company_add.operate=1;
            $.ajax({
                type : "post",
                url: url("company/find"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify({id:id}),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        company_add.id=result.data.id;
                        company_add.name=result.data.name;
                        company_add.companyType=result.data.companyType;
                        company_add.remark=result.data.remark;
                        company_add.abb=result.data.abb;
                    }
                }
            });
            root.load('company_add.html',13);
        },
        goSave:function(){
            company_add.operate=0;
            company_add.id="";
            company_add.name="";
            company_add.companyType="";
            company_add.remark="";
            company_add.abb="";
            root.load('company_add.html',13);
        },
        page: function(){

            company_list.pageNum = paging.pageNum;
            company_list.pageSize = paging.pageSize;
            $.ajax({
                type : "post",
                url: url("company/page"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify(company_list.$model),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        paging.pageNum = result.data.pageNum;
                        paging.pageSize = result.data.pageSize;
                        paging.pageCount = result.data.pageCount;
                        paging.total = result.data.total;
                        company_list.company_list = result.data.list;
                        paging.pageNum = result.data.pageNum;
                        paging.pageSize = result.data.pageSize;
                        paging.pageCount = result.data.pageCount;
                        paging.total = result.data.total;
                    }
                }
            });
        },
        allCompanyList:function(){
            $.ajax({
                type : "post",
                url: url("company/page"),
                dataType : 'json',
                contentType:'application/json',
                data: {pageNum:paging.firstPageNum,pageSize:paging.maxSize},
                success : function(result) {
                    if(result.code=="000000")
                    {
                        user_add.companyList = result.data.list;
                    }
                }
            });
        }
    });

    /*************************添加公司*****************************/
    var company_add = avalon.define({
        $id:'company_add',
        id:"",
        name:"",
        companyType:"",
        remark:"",
        abb:"",
        saveStatus:0,
        errorMessage:"",
        operate:"",//操作：0-添加，1-修改
        save: function(){
            $.ajax({
                type : "post",
                url: url("company/add"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify(company_add.$model),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        company_add.id="";
                        company_add.name="";
                        company_add.abb="";
                        company_add.companyType="";
                        company_add.remark="";
                        company_add.saveStatus=1;
                    }else{
                        company_add.saveStatus=2;
                        company_add.errorMessage=result.message;
                    }
                }
            });
        },
        update: function(){
            $.ajax({
                type : "post",
                url: url("company/update"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify(company_add.$model),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        company_add.id="";
                        company_add.name="";
                        company_add.abb="";
                        company_add.companyType="";
                        company_add.remark="";
                        root.load("company_list.html",13);
                    }else{
                        company_add.saveStatus=2;
                        company_add.errorMessage=result.message;
                    }
                }
            });
        }
    });
    /*************************添加用户*****************************/
	var user_add = avalon.define({
		$id:'user_add',
		id:"",
		userName:"",
		trueName:"",
        phone:"",
        companyId:"",
        companyPointId:"",
        userType:"",
        saveStatus:0,
        code:"",
        errorMessage:"",
        addUserRoleList:[],
        companyList:[],
        companyPointList:[],
        operate:0,
        companyName:"",
        companyPointName:"",
        initRoleList:function(){
		    if(user_add.operate==0){
                $.ajax({
                    type : "post",
                    url: url("role/listAddUserRole"),
                    dataType : 'json',
                    contentType:'application/json',
                    success : function(result) {
                        if(result.code=="000000")
                        {
                            user_add.addUserRoleList=result.data;
                        }
                    }
                });
            }
        },
        initCompany:function(){
            $.ajax({
                type : "post",
                url: url("company/page"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify({pageNum:paging.firstPageNum,pageSize:paging.maxSize,companySearchType:1}),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        user_add.companyList=result.data.list;
                    }
                }
            });
        },
        changeCompany:function(){

            $.ajax({
                type : "post",
                url: url("company/pagePoint"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify({companyId:user_add.companyId,pageNum:paging.firstPageNum,pageSize:paging.maxSize,companyPointSearchType:1}),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        user_add.companyPointList = result.data.list;
                    }
                }
            });
        },
		save: function(){
            var addUserRoleList = user_add.addUserRoleList;
            if(addUserRoleList!=[]){
                for(var o in addUserRoleList){
                    var role = addUserRoleList[o];
                    role.pass= role.pass==0||role.pass==undefined||role.pass==false?0:1;
                }
            }
			$.ajax({
				type : "post",
				url: url("user/add"),
				dataType : 'json',
                contentType:'application/json',
				data: JSON.stringify(user_add.$model),
				success : function(result) {
					if(result.code=="000000")
					{
                        user_add.id="";
                        user_add.userName="";
                        user_add.trueName="";
                        user_add.phone="";
                        user_add.userType="";
                        user_add.code=result.data.code;
                        user_add.saveStatus=1;
					}else{
                        user_add.saveStatus=2;
                        user_add.errorMessage=result.message;
					}
				}
			});
		},
        update: function(){

            var addUserRoleList = user_add.addUserRoleList;
            if(addUserRoleList!=[]){
                for(var o in addUserRoleList){
                    var addUserRole = addUserRoleList[o];
                    addUserRole.pass= addUserRole.pass==0||addUserRole.pass==undefined||addUserRole.pass==false?0:1;
                }
            }
            $.ajax({
                type : "post",
                url: url("user/update"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify(user_add.$model),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        user_add.id="";
                        user_add.userName="";
                        user_add.trueName="";
                        user_add.phone="";
                        user_add.userType="";
                        user_add.code=result.data.code;
                        root.load("user_list.html");
                    }else{
                        user_add.saveStatus=2;
                        user_add.errorMessage=result.message;
                    }
                }
            });
        }
	});
    /*************************用户列表*****************************/
    var user_list = avalon.define({
        $id:'user_list',
        trueName:"",
        code:"",
        phone:"",
        userType:"",
        userList:[],
        pageNum:"",
        pageSize:"",
        page: function(){
            user_list.pageNum = paging.pageNum;
            user_list.pageSize = paging.pageSize;
            $.ajax({
                type : "post",
                url: url("user/page"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify(user_list.$model),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        var list = result.data.list;
                        for(var o in list){
                            var roleList = list[o].roleList;
                            var size = roleList.length;
                            for(var i in roleList){
                                var name = roleList[i].name;
                                roleList[i].name=size-i>1?name+",":name;
                            }
                        }
                        user_list.userList = result.data.list;
                        paging.pageNum = result.data.pageNum;
                        paging.pageSize = result.data.pageSize;
                        paging.pageCount = result.data.pageCount;
                        paging.total = result.data.total;
                    }
                }
            });
        },
        removeItem:function(id){
            if(confirm("确定删除本条数据？")){
                $.ajax({
                    type : "post",
                    url: url("user/delete"),
                    dataType : 'json',
                    contentType:'application/json',
                    data: JSON.stringify({id:id}),
                    success : function(result) {
                        if(result.code=="000000")
                        {
                            paging.pageNum=1;
                            user_list.page();
                        }
                    }
                });
            }
        },
        goUpdate:function(id){
            user_add.operate=1;
            user_add.saveStatus="";
            $.ajax({
                type : "post",
                url: url("user/find"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify({id:id}),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        user_add.id=result.data.id;
                        user_add.userName=result.data.userName;
                        user_add.trueName=result.data.trueName;
                        user_add.phone=result.data.phone;
                        user_add.companyId=result.data.companyId;
                        user_add.userType=result.data.userType;
                        user_add.companyName=result.data.companyName;
                        user_add.companyPointName=result.data.companyPointName;
                        user_add.addUserRoleList = result.data.addUserRoleList;
                        user_add.changeCompany();
                        user_add.companyPointId=result.data.companyPointId;
                    }
                }
            });
            root.load('user_add.html',8);
        },
        goSave:function(){
            user_add.operate=0;
            user_add.id="";
            user_add.userName="";
            user_add.trueName="";
            user_add.phone="";
            user_add.companyId="";
            user_add.companyPointId="";
            user_add.userType="";
            user_add.saveStatus="";
            root.load('user_add.html',8);
        },
    });
    /*************************添加车辆*****************************/
    var car_add = avalon.define({
        $id:'car_add',
        userName:"",
        trueName:"",
        code:"",
        saveStatus:0,
        errorMessage:"",
        save: function(){
            $.ajax({
                type : "post",
                url: url("car/add"),
                dataType : 'json',
                contentType:'application/json',
                data: {userName:user_add.userName,trueName:user_add.trueName,phone:user_add.phone,companyPointId:user_add.companyPointId},
                success : function(result) {
                    if(result.code=="000000")
                    {
                        user_add.userName="";
                        user_add.trueName="";
                        user_add.phone="";
                        user_add.saveStatus=1;
                        user_add.code=result.data.code;
                    }else{
                        user_add.saveStatus=2;
                        user_add.errorMessage=result.message;
                    }
                }
            });
        }
    });
    /*************************车辆列表*****************************/
    var car_list = avalon.define({
        $id:'car_list',
        trueName:"",
        phone:"",
        userList:[],
        save: function(){
            $.ajax({
                type : "post",
                url: url("car/page"),
                dataType : 'json',
                contentType:'application/json',
                data: {trueName:user_list.trueName,phone:user_list.phone,pageNum:paging.pageNum,pageSize:paging.pageSize},
                success : function(result) {
                    if(result.code=="000000")
                    {
                        user_list.userList = result.data.list;
                    }
                }
            });
        }
    });
	/*************************站点列表*****************************/
	var company_point_list = avalon.define({
		$id:'company_point_list',
		company_point_list:[],
        companyList:[],
		companyType:"",
		companyId:"",
        operate:"",
        pageNum:"",
        pageSize:"",
        companyPointSearchType:2,
        initCompany:function(){
            $.ajax({
                type : "post",
                url: url("company/page"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify({pageNum:paging.firstPageNum,pageSize:paging.maxSize,companySearchType:2}),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        company_point_list.companyList=result.data.list;
                    }
                }
            });
        },
		removeItem:function(id){
			if(confirm("确定删除本条数据？")){
				$.ajax({
					type : "post",
					url: url("company/deletePoint"),
					dataType : 'json',
                    contentType:'application/json',
					data: JSON.stringify({id:id}),
					success : function(result) {
						if(result.code=="000000")
						{
							paging.pageNum=1;
							company_point_list.page();
						}
					}
				});
			}
		},
        goUpdate:function(id){
            company_point_add.operate=1;
            company_point_add.saveStatus=0;
            $.ajax({
                type : "post",
                url: url("company/findPoint"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify({id:id}),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        company_point_add.id=result.data.id;
                        company_point_add.name=result.data.name;
                        company_point_add.address=result.data.address;
                        company_point_add.companyType=result.data.companyType;
                        company_point_add.companyId=result.data.companyId;
                        company_point_add.companyName=result.data.companyName;
                        company_point_add.shortName=result.data.shortName;
                        company_point_add.remark=result.data.remark;
                    }
                }
            });
            root.load('company_point_add.html',14);
        },
        goSave:function(){
            company_point_add.operate=0;
            company_point_add.saveStatus=0;
            company_point_add.id="";
            company_point_add.name="";
            company_point_add.address="";
            company_point_add.companyType="";
            company_point_add.companyId="";
            company_point_add.companyName="";
            company_point_add.shortName="";
            company_point_add.remark="";
            root.load('company_point_add.html',14);
        },
		page: function(){
            company_point_list.pageNum = paging.pageNum;
            company_point_list.pageSize = paging.pageSize;
			$.ajax({
				type : "post",
				url: url("company/pagePoint"),
				dataType : 'json',
                contentType:'application/json',
				data: JSON.stringify(company_point_list.$model),
				success : function(result) {
					if(result.code=="000000")
					{
						var itemList = result.data.list;
						company_point_list.company_point_list = itemList;
						paging.pageNum = result.data.pageNum;
						paging.pageSize = result.data.pageSize;
						paging.pageCount = result.data.pageCount;
						paging.total = result.data.total;
					}
				}
			});
		}
	});
	/*************************添加站点*****************************/
	var company_point_add = avalon.define({
		$id:'company_point_add',
		id:"",
		name:"",
		address:"",
		companyType:"",
		companyName:"",
		companyId:"",
		shortName:"",
		remark:"",
        saveStatus:0,
        operate:"",
        errorMessage:"",
		company_list:[],
		changeCompanyType:function(){
			$.ajax({
				type : "post",
				url: url("company/page"),
				dataType : 'json',
                contentType:'application/json',
				data: JSON.stringify({type:company_point_add.companyType,pageNum:paging.firstPageNum,pageSize:paging.maxSize,companySearchType:2}),
				success : function(result) {
					if(result.code=="000000")
					{
						company_point_add.company_list = result.data.list;
					}
				}
			});
		},
		save: function(){
			$.ajax({
				type : "post",
				url: url("company/addPoint"),
				dataType : 'json',
                contentType:'application/json',
				data: JSON.stringify(company_point_add.$model),
				success : function(result) {
					if(result.code=="000000")
					{
                        company_point_add.saveStatus=1;
					}else{
                        company_point_add.saveStatus=2;
                        company_point_add.errorMessage=result.message;
					}
				}
			});
		},
        update: function(){
            $.ajax({
                type : "post",
                url: url("company/updatePoint"),
                dataType : 'json',
                contentType:'application/json',
                data: JSON.stringify(company_point_add.$model),
                success : function(result) {
                    if(result.code=="000000")
                    {
                        root.load("company_point_list.html",14);
                    }else{
                        company_point_add.saveStatus=2;
                        company_point_add.errorMessage=result.message;
                    }
                }
            });
        }
	});

	/**************************expand_content************************************/

	var expand_content = avalon.define({
		$id:'expand_content',
		state:"0",
		expand_content: function(){

			if(expand_content.state==0){
				$(".block_left").hide(180);
				// $(".block_left").
				$(".block_right").css("margin-left","0px");
				expand_content.state=1
			}else{
				// $(".block_left").show();
				$(".block_left").show(180);
				$(".block_right").css("margin-left","246px");
				expand_content.state=0
			}
		}
	});
    /**************************顶部************************************/

    var top_box = avalon.define({
        $id:'top_box',
        trueName:sessionStorage.trueName,
        companyPointName:sessionStorage.companyPointName,
        trackingNumber:"",
        logout:function(){
            if(confirm("确认退出快哥云仓？")){
                $.ajax({
                    type : "post",
                    url: url("user/logout"),
                    dataType : 'json',
                    contentType:'application/json',
                    success : function(result) {
                        if(result.code=="000000")
                        {
                            sessionStorage.clear();
                            top.location.href=request_base_url;
                        }
                    }
                });
            }
        },
        searchTracking:function(event){
            if (event.keyCode == "13") {//keyCode=13是回车键){
                if($.trim(top_box.trackingNumber)!=""){
                    root.load('tracking_flow.html',18);
                    tracking_flow.trackingNumber = top_box.trackingNumber;
                    tracking_flow.goGetInfo();
                }
            }
        }
    });
    /**************************首页统计************************************/

    var home = avalon.define({
        $id:'home',
        review:0,
        todayInCount:0,
        todayOutCount:0,
        todaySignedCount:0,
        todayBackOutCount:0,
        todayBackCount:0,
        init:function(){
            //云仓用户
            if(sessionStorage.userType==3){
                $.ajax({
                    type : "post",
                    url: url("home/cloudCount"),
                    dataType : 'json',
                    contentType:'application/json',
                    success : function(result) {
                        if(result.code=="000000")
                        {
                            home.todayInCount=result.data.todayInCount;
                            home.todayOutCount=result.data.todayOutCount;
                            home.todaySignedCount=result.data.todaySignedCount;
                            home.todayBackOutCount=result.data.todayBackOutCount;
                            home.todayBackCount=result.data.todayBackCount;
                        }
                    }
                });
            }
        },
        searchTrackingToday:function(event,status){
            send_pieces_search.status = status==-1?"":status;
            send_pieces_search.initDate = status==-1?0:1;
            event.stopPropagation();
            root.load('send_pieces_search.html',6);
        }
    });
    /**************************修改密码***********************************/

        var change_password = avalon.define({
            $id:'change_password',
            oldPassword:"",
            newPassword:"",
            againPassword:"",
            saveStatus:0,
            errorMessage:"",
            oldPassword_tip:"",
            newPassword_tip:"",
            againPassword_tip:"",
            changePassword:function(){
                change_password.oldPassword_tip="";
                change_password.newPassword_tip="";
                change_password.againPassword_tip="";
                if(change_password.oldPassword==""){
                    change_password.oldPassword_tip = "请输入原密码";
                    return;
                }
                if(change_password.oldPassword.length<6){
                    change_password.oldPassword_tip = "原密码错误";
                    return;
                }
                if(change_password.newPassword==""){
                    change_password.newPassword_tip = "请输入新密码";
                    return;
                }
                if(change_password.newPassword.length<6){
                    change_password.newPassword_tip = "新密码长度最少为6";
                    return;
                }
                if(change_password.newPassword!=change_password.againPassword){
                    change_password.againPassword_tip = "两次密码输入不一致";
                    return;
                }


                $.ajax({
                    type : "post",
                    url: url("user/changePassword"),
                    dataType : 'json',
                    contentType:'application/json',
                    data:JSON.stringify({oldPassword:change_password.oldPassword,newPassword:change_password.newPassword}),
                    success : function(result) {
                        if(result.code=="000000")
                        {
                            change_password.saveStatus=1;
                        }else{
                            change_password.saveStatus=2;
                            change_password.errorMessage=result.message;
                        }
                    }
                });
            }
        });

	var root = avalon.define({
		$id:'root',
		left: "../html/left.html",
		top:  "../html/top.html",
		noPower:  "../html/power_tip.html",
		content: sessionStorage.page_now?sessionStorage.page_now:"../html/blank.html",
		table_footer:"table_footer.html",
        signed_scan:function(){
            sessionStorage.tracking_status=2;
            root.load('home_cloud.html');
            root.load('tracking_add.html',3);
        },
		load: function(page,id,isHistory){

            if(page==""){
                return;
            }
			sessionStorage.history_nav = sessionStorage.nav_now;
			if(id){
				$(".check").removeClass("check");
				$("#"+id).parent().addClass("check");
				$("#"+id).parent().parent().show();
				$("#"+id).parent().parent().parent().children(":first").find(".point_box").removeClass("point_down").addClass("point_up");
				sessionStorage.nav_now = id;
			}else{
				$(".check").removeClass("check");
				$(".nav_second_box").css("display","none");
				$(".point_up").removeClass("point_up").addClass("point_down");
				sessionStorage.nav_now = "";
			}
            // root.content=page==""?"#":"../html/"+page;
            root.content="";
            root.content=page;
            sessionStorage.page_now = '../html/'+page;
			sessionStorage.history = sessionStorage.page;
            sessionStorage.page = page;
            if(isHistory){
                sessionStorage.isHistoryClick = isHistory;
            }else{
                sessionStorage.isHistoryClick = false;
            }

		},
		history:function(){
			$(".point_up").removeClass("point_up").addClass("point_down");
			$(".nav_second_box").hide();
            paging.pageNum=sessionStorage.historyPageNum;
            paging.pageSize=sessionStorage.historyPageSize;
            paging.pageCount=sessionStorage.historyPageCount;
            paging.total=sessionStorage.historyTotalCount;
			root.load(sessionStorage.history,sessionStorage.history_nav,true);
		},
		init:function(){
            login.getUserSession();
            sessionStorage.historyPageNum = paging.pageNum;
            sessionStorage.historyPageSize = paging.pageSize;
            sessionStorage.historyPageCount = paging.pageCount;
            sessionStorage.historyTotalCount = paging.total;

            if(sessionStorage.page=="cloud_back_person.html"){
                cloud_back_person.userCode="";
                sessionStorage.tracking_status=3;
                sessionStorage.operationName="返仓扫描";
                $("#goScan").focus();
            }
            if(sessionStorage.page=="cloud_back_out_person.html"){
                cloud_back_out_person.userCode="";
                sessionStorage.tracking_status=4;
                sessionStorage.operationName="退件扫描";
                $("#goScan").focus();
            }

			if(sessionStorage.page=="cloud_in_person.html"){
                cloud_in_person.isError="";
                cloud_in_person.driverName="";
                cloud_in_person.code="";
			}
            if(sessionStorage.page=="cloud_out_person.html"){
                cloud_out_person.isError="";
                cloud_out_person.code="";
            }
			if(sessionStorage.page=="send_pieces_search.html"){
                $('#tracking_start').prop("readonly", true).datetimepicker({
                    lang:'ch',
                    format:'Y-m-d',
                    timepicker:false //关闭时间选项
                });
                $('#tracking_end').prop("readonly", true).datetimepicker({
                    lang:'ch',
                    format:'Y-m-d',
                    timepicker:false  //关闭时间选项
                });
                if(send_pieces_search.initDate==1){
                    $('#tracking_start').val(formatToday());
                }

                send_pieces_search.cloudId="";
                send_pieces_search.cloudPointId="";
                send_pieces_search.srcCompanyId="";
                send_pieces_search.srcCompanyPointId="";
                paging.pageNum = 1;
                paging.pageSize = 10;
                //超级管理员、全部站点列表权限者、云仓用户、跑腿公司用户 初始化快递公司列表
                if(sessionStorage.userType==4||sessionStorage.userPower_companyPointListAll==1||sessionStorage.companyType==0||sessionStorage.companyType==1){
                    send_pieces_search.initSrcCompany();
                }
                //超级管理员、全部站点列表权限者、跑腿公司用户、快递公司用户且有本站点站点列表权限、快递公司用户且有本公司站点列表权限 初始化云仓列表

                if(sessionStorage.userType==4||sessionStorage.userPower_companyPointListAll==1||sessionStorage.companyType==0||(sessionStorage.companyType==2&&sessionStorage.userPower_companyPointListCompany==1)||(sessionStorage.companyType==2&&sessionStorage.userPower_companyPointListCompanyPoint==1)){
                    send_pieces_search.initCloud();
                }
                //超级管理员、全部站点列表权限者、云仓用户、快递公司用户且有本站点站点列表权限、快递公司用户且有本公司站点列表权限 初始化跑腿公司列表
                if(sessionStorage.userType==4||sessionStorage.userPower_companyPointListAll==1||sessionStorage.companyType==1||(sessionStorage.companyType==2&&sessionStorage.userPower_companyPointListCompany==1)||(sessionStorage.companyType==2&&sessionStorage.userPower_companyPointListCompanyPoint==1)){
                    send_pieces_search.initSend();
                }
                //快递公司用户且具有公司权限的初始化快递公司站点列表
                if(sessionStorage.companyType==2&&sessionStorage.userPower_companyPointListCompany==1){
                    send_pieces_search.initSrcCompanyPoint();
                }
                //云仓用户且具有公司权限的初始化云仓站点列表
                if(sessionStorage.companyType==1&&sessionStorage.userPower_companyPointListCompany==1){
                    send_pieces_search.initCloudPoint();
                }
                //跑腿公司用户且具有公司权限的初始化跑腿公司站点列表
                if(sessionStorage.companyType==0&&sessionStorage.userPower_companyPointListCompany==1){
                    send_pieces_search.initSendPoint();
                }
                send_pieces_search.page();
                send_pieces_search.initDate = 0;
			}
			if(sessionStorage.page=="company_list.html"){
				paging.pageNum = 1;
                paging.pageSize = 10;
				company_list.type="";
				company_list.page();
			}
			if(sessionStorage.page=="role_list.html"){
				paging.pageNum = 1;
                paging.pageSize = 10;
                role_list.page();
			}
			if(sessionStorage.page=="company_add.html"){
                company_add.saveStatus = 0;
			}
            if(sessionStorage.page=="role_add.html"){
                role_add.saveStatus = 0;
            }
			if(sessionStorage.page=="company_point_list.html"){
				paging.pageNum = 1;
                paging.pageSize = 10;
				company_point_list.companyId="";
				company_point_list.companyType="";
                company_point_list.initCompany();
				company_point_list.page();
			}
            if(sessionStorage.page=="user_list.html"){
                paging.pageNum = 1;
                paging.pageSize = 10;
                user_list.trueName="";
                user_list.phone="";
                user_list.userType="";
                user_list.page();
            }
            if(sessionStorage.page=="function_role.html"){
                function_role.roleId="";
                role_list.listRole();
            }
			if(sessionStorage.page=="tracking_add.html"){
                tracking_add.trackingNumber="";
                $("#trackingNumber").focus();
				tracking_add.tracking_list=[];
                tracking_add.successCount=0;
                tracking_add.isCollect=0;
                tracking_add.userCode=sessionStorage.tracking_add_userCode;
                tracking_add.trueName=sessionStorage.tracking_add_trueName;
                tracking_add.userCodePreLabel=sessionStorage.tracking_add_userCodePreLabel;
                tracking_add.companyPointShortName=sessionStorage.tracking_add_companyPointShortName;
			}
            if(sessionStorage.page=="tracking_add_signed.html"){
                tracking_add.trackingNumber="";
                tracking_add.collectMoney="";
                $("#trackingNumber").focus();
                sessionStorage.tracking_status=2;
                tracking_add.status=2;
                tracking_add.tracking_list=[];
                tracking_add.successCount=0;
            }
            if(sessionStorage.page=="tracking_add_back.html"){
                sessionStorage.tracking_status=3;
                tracking_add_back.status=3;
                tracking_add_back.tracking_list=[];
                tracking_add_back.successCount=0;
                tracking_add_back.trackingNumber="";
                tracking_add_back.problem="";
                $("#trackingNumber").focus();
            }
            if(sessionStorage.page=="tracking_add_back_out.html"){
                sessionStorage.tracking_status=4;
                tracking_add_back_out.status=4;
                tracking_add_back_out.tracking_list=[];
                tracking_add_back_out.successCount=0;
                tracking_add_back_out.trackingNumber="";
                $("#trackingNumber").focus();
            }
            if(sessionStorage.page=="user_add.html"){
                //新增时用到
                user_add.initRoleList();
                user_add.initCompany();
            }
            if(sessionStorage.page=="home_cloud.html"){
                home.init();
            }
            if(sessionStorage.page=="tracking_batch_signed.html"){
                tracking_batch_signed.senderCode="";
                $("#senderCode").focus();
                $('#tracking_start').prop("readonly", true).datetimepicker({
                    lang:'ch',
                    format:'Y-m-d',
                    value:formatToday(),
                    timepicker:false //关闭时间选项
                });
                $('#tracking_end').prop("readonly", true).datetimepicker({
                    lang:'ch',
                    format:'Y-m-d',
                    value:formatToday(),
                    timepicker:false  //关闭时间选项
                });
            }
            // if(sessionStorage.page=="home_other.html"){
            //     home.init();
            // }
            if(sessionStorage.page=="collect.html"){
                $("#money").focus();
                if(collect.tracking_number!=""){
                    $("#collect_tracking_number").attr("readonly","true");
                    $("#collect_tracking_number").addClass("readonly");
                }
            }
		}
	});

    function formatToday(){
        var today = new Date();
        var str = "" + today.getFullYear() + "-";
        str += (today.getMonth()+1) + "-";
        str += today.getDate();
        return str;
    }
    $.ajaxSetup({
        complete:function(XMLHttpRequest){
            var sessionStatus=XMLHttpRequest.getResponseHeader("sessionStatus");
            var path=XMLHttpRequest.getResponseHeader("path");
            if(sessionStatus=="timeout")
            {
                sessionStorage.clear();
                //如果超时就处理 ，指定要跳转的页面
                top.location.href=request_base_url;
            }else if(sessionStatus=="noPower")
            {
                alert("权限不足，请联系管理员！");
            }
        }
    });
	avalon.scan(document.body);
});
